home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2000 January / maximum-cd-2000-01.iso / Dreamweaver2 / data1.cab / Program_Files / Configuration / Behaviors / Actions / Timeline / Play Timeline.js < prev    next >
Encoding:
JavaScript  |  1999-02-23  |  5.4 KB  |  152 lines

  1. //*************** GLOBALS VARS *****************
  2.  
  3. //******************* BEHAVIOR FUNCTION **********************
  4.  
  5. //Starts a timeline playing from the current frame.
  6. //Accepts the following arguments:
  7. //  tmLnName - the name of the timeline to play (ex: Timeline1)
  8. //
  9. //Designed to work in conjunction with Dreamweaver's Timeline Inspector.
  10. //The Timeline Inspector creates a JS function called MM_initTimelines(),
  11. //which puts all the timeline settings in a multidimensional array, saved
  12. //into a document property called document.MM_Time.
  13. //
  14. //My function initializes the timeline by calling MM_initTimelines.
  15. //Next it starts a timer using setTimeout(), which recursively calls this
  16. //again after the elapsed time. I use myID to identify recursive calls.
  17. //Then it checks the data arrays and sets all sprites to their new positions
  18. //and sets other properties. For behavior sprites it evals the behavior call.
  19.  
  20. function MM_timelinePlay(tmLnName, myID) { //v1.2
  21.   //Copyright 1997 Macromedia, Inc. All rights reserved.
  22.   var i,j,tmLn,props,keyFrm,sprite,numKeyFr,firstKeyFr,propNum,theObj,firstTime=false;
  23.   if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
  24.   tmLn = document.MM_Time[tmLnName];
  25.   if (myID == null) { myID = ++tmLn.ID; firstTime=true;}//if new call, incr ID
  26.   if (myID == tmLn.ID) { //if Im newest
  27.     setTimeout('MM_timelinePlay("'+tmLnName+'",'+myID+')',tmLn.delay);
  28.     fNew = ++tmLn.curFrame;
  29.     for (i=0; i<tmLn.length; i++) {
  30.       sprite = tmLn[i];
  31.       if (sprite.charAt(0) == 's') {
  32.         if (sprite.obj) {
  33.           numKeyFr = sprite.keyFrames.length; firstKeyFr = sprite.keyFrames[0];
  34.           if (fNew >= firstKeyFr && fNew <= sprite.keyFrames[numKeyFr-1]) {//in range
  35.             keyFrm=1;
  36.             for (j=0; j<sprite.values.length; j++) {
  37.               props = sprite.values[j]; 
  38.               if (numKeyFr != props.length) {
  39.                 if (props.prop2 == null) sprite.obj[props.prop] = props[fNew-firstKeyFr];
  40.                 else        sprite.obj[props.prop2][props.prop] = props[fNew-firstKeyFr];
  41.               } else {
  42.                 while (keyFrm<numKeyFr && fNew>=sprite.keyFrames[keyFrm]) keyFrm++;
  43.                 if (firstTime || fNew==sprite.keyFrames[keyFrm-1]) {
  44.                   if (props.prop2 == null) sprite.obj[props.prop] = props[keyFrm-1];
  45.                   else        sprite.obj[props.prop2][props.prop] = props[keyFrm-1];
  46.         } } } } }
  47.       } else if (sprite.charAt(0)=='b' && fNew == sprite.frame) eval(sprite.value);
  48.       if (fNew > tmLn.lastFrame) tmLn.ID = 0;
  49.   } }
  50. }
  51.  
  52. //******************* API **********************
  53.  
  54. //Checks for the existence of timelines.
  55. //If none exist, returns false so this Action is grayed out.
  56.  
  57. function canAcceptBehavior(){
  58.   var allScripts,i,theScript,timelineExists;
  59.  
  60.   timelineExists = false;
  61.   allScripts = getObjectTags("document","script");
  62.   for (i in allScripts) {
  63.     theScript = ""+allScripts[i];
  64.     if (theScript.indexOf("function MM_initTimelines") != -1) {
  65.       timelineExists = true;
  66.       break;
  67.   } }
  68.   return (timelineExists);
  69. }
  70.  
  71.  
  72.  
  73. //Returns a Javascript function to be inserted in HTML head with script tags.
  74.  
  75. function behaviorFunction(){
  76.   return "MM_timelinePlay";
  77. }
  78.  
  79.  
  80.  
  81. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  82. //Returns one arg: the selected timeline name.
  83.  
  84. function applyBehavior() {
  85.   menuIndex = document.theForm.menu.selectedIndex;  //get menu selection index
  86.   timelineName = document.theForm.menu.options[menuIndex].text; //gets selected string
  87.   return "MM_timelinePlay('"+timelineName+"')";
  88. }
  89.  
  90.  
  91.  
  92. //Passed the function call above, extracts the args and reloads the UI.
  93. //With arg timelineName, scans the menu for a matching item, and selects it.
  94. //If the name is not found, it gives an error msg.
  95.  
  96. function inspectBehavior(upStr){
  97.   var timelineName,menuLength,i;
  98.   var argArray = new Array;
  99.   var found = false;
  100.  
  101.   argArray = extractArgs(upStr); //get args
  102.   if (argArray.length == 2) {  //should be exactly 2 arg (first arg is fn name)
  103.     timelineName = argArray[1];
  104.     menuLength = document.theForm.menu.options.length;
  105.     for (var i=0; i<menuLength; i++) {  //search menu for matching timeline name
  106.       if (document.theForm.menu.options[i].text == timelineName) { //if found
  107.         document.theForm.menu.selectedIndex = i;  //make it selected
  108.         found = true;
  109.         break;
  110.       }
  111.     }
  112.     if (!found) alert(errMsg(MSG_TimelineNotFound,timelineName));
  113.   }
  114. }
  115.  
  116.  
  117.  
  118. //***************** LOCAL FUNCTIONS  ******************
  119.  
  120.  
  121. //Load the select menu with timeline names.
  122.  
  123. function initializeUI(){
  124.   var i,j,startPos,endPos,theName,theScript;
  125.   var menuIndex = 0;
  126.   var allScripts = new Array;
  127.  
  128.   allScripts = getObjectTags("document","script");
  129.   for (i in allScripts) {
  130.     theScript = ""+allScripts[i];
  131.     if (theScript.indexOf("function MM_initTimelines") != -1) {
  132.       j = theScript.indexOf('].MM_Name');
  133.       while (j != -1) {
  134.         startPos = theScript.indexOf('"',++j);
  135.         endPos = theScript.indexOf('"',++startPos);
  136.         if (0 < startPos && startPos < endPos) {
  137.           theName = theScript.substring(startPos,endPos);
  138.           document.theForm.menu.options[menuIndex++] = new Option(theName);
  139.         }
  140.         j = theScript.indexOf('].MM_Name',j+1);
  141.       }
  142.     }
  143.   }
  144. }
  145.  
  146.  
  147.  
  148. //**************** GENERIC FUNCTIONS ****************
  149.  
  150. //function extractArgs(upStr){
  151. //function errMsg() {
  152.